//
//  ESLaetedJokesSearchDetailCell.m
//  EasyStyle
//
//  Created by FK on 16/5/14.
//  Copyright © 2016年 FK. All rights reserved.
//

#import "ESLaetedJokesSearchDetailCell.h"

@implementation ESLaetedJokesSearchDetailCell

- (void)awakeFromNib {
    self.bgView.alpha = 0.8;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
    [super setSelected:selected animated:animated];
    
    self.bgView.backgroundColor = [UIColor colorWithHex:_jokesItem.colorHex];
    
    self.jokesContent.font = ESFontWithSize(14);
    self.jokesContent.numberOfLines = 0;
    self.jokesContent.text = [ESLaetedJokesSearchDetailCell filtrateUselessWord:_jokesItem.content];
    
}

+ (NSString *)filtrateUselessWord:(NSString *)sourceString
{
    NSString *aString = @"\r\n";
    NSString *bString = @"&#160;";
    NSString *filtratedStr = [sourceString stringByReplacingOccurrencesOfString:@"\\r\\n" withString:aString];
    filtratedStr = [filtratedStr stringByReplacingOccurrencesOfString:bString withString:@" "];
    
    return filtratedStr;
}

+ (CGFloat)getHeightCellWithContent:(NSString *)jokesContent;
{
    NSStringDrawingOptions options =  NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
    
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    [style setLineBreakMode:NSLineBreakByCharWrapping];
    
    NSDictionary *attributes = @{ NSFontAttributeName : ESFontWithSize(14), NSParagraphStyleAttributeName : style };
    
    CGRect contentLabelSize = [[ESLaetedJokesSearchDetailCell filtrateUselessWord:jokesContent] boundingRectWithSize:CGSizeMake(ScreenWidth-20, CGFLOAT_MAX) options:options attributes:attributes context:nil];
        
    CGFloat height = contentLabelSize.size.height + 25;
    
    if (height < 110) {
        return 110;
    }
    return  height;
//    [self setHeight:contentLabelSize.size.height + 16];    // 16 是纵向间隙和
}


@end
